from functools import partial

students = [
    {"name": "Alice", "age": 25, "score": 85},
    {"name": "Bob", "age": 22, "score": 90},
    {"name": "Charlie", "age": 23, "score": 88},
]

def custom_sort(data, key, reverse=False):
    # 使用sorted函数对数据进行排序
    # key参数指定排序的依据，reverse参数决定排序顺序（升序或降序）
    return sorted(data, key=lambda student: student[key], reverse=reverse)


# 根据年龄排序
sorted_by_age = custom_sort(students, key="age")
print(sorted_by_age)
# 输出: [{'name': 'Bob', 'age': 22, 'score': 90}, {'name': 'Charlie', 'age': 23, 'score': 88}, {'name': 'Alice', 'age': 25, 'score': 85}]

#根据成绩排序
sorted_by_score = custom_sort(students, key="score")
print(sorted_by_score)
# # 输出: [{'name': 'Alice', 'age': 25, 'score': 85}, {'name': 'Charlie', 'age': 23, 'score': 88}, {'name': 'Bob', 'age': 22, 'score': 90}]
